//可以进行多次读写
#include"func.h"
int main(int argc,char *argv[]){
    // ./my_cpy file3 file4
    ARGS_CHECK(argc,3);
    int fdr = open(argv[1],O_RDONLY);
    ERROR_CHECK(fdr,-1,"open");
    //如果是要连续写入，每次写入时就不应该把之前的内容覆盖掉
    int fdw = open(argv[2],O_WRONLY|O_CREAT,0666);
    ERROR_CHECK(fdw,-1,"open");
    
    char buff[4]={0};
    ssize_t sret = 0;
    //如果当sret不等于0，肯定还有数据没有读完，所以继续读写
    while((sret = read(fdr,buff,sizeof(buff)))!=0){
        memset(buff,0,sizeof(buff));
        write(fdw,buff,sret);
        puts("the file is over");
        if(sret==0){
            break;
        }
    }
    //ssize_t sret = read(fdr,buff,sizeof(buff));
    //有多少写多少，所以直接调用sret能够将所有的数据都写入到fdw中
    printf("%ld\n",sret);

    close(fdr);
    close(fdw);
    return 0;

}
